<!--
 * 抽取比例设置
-->
<template>
    <div class="con color">
        <div>
          <ConditionCard shadow="never" body-style="padding: 24px 24px 6px 24px;" @search="onSubmit" @reset="reset()">
            <el-form ref="queryForm" :model="queryForm" label-suffix="：" label-position="right" label-width="90px">
              <el-row :gutter="24">
                <el-col :span="8">
                  <el-form-item :label="$t('label.college')">
                    <el-select
                      v-model="queryForm.academyCode"
                      style="width: 100%;"
                      clearable
                      filterable
                      :placeholder="$t('common.text.all')"
                      v-clearreadonly
                    >
                      <el-option
                          v-for="item in options.academyCode"
                          :key="item.value"
                          :label="item.label"
                          :value="item.value"
                      />
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item :label="$t('paperBlindTrial.batchName')" >
                    <el-input v-model="queryForm.batchNo" :placeholder="$t('common.pla.pleaseInput')" :maxlength="255" :clearable="true"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
          </ConditionCard>
          <el-card shadow="never">
            <el-row  type="flex" justify="space-between" class="btn_row">
              <el-col :span="8">
                <h1 class="condition-title">{{$t('paperBlindTrial.applyTimeTitle')}}</h1>
              </el-col>
              <el-col :span="4" style="text-align: right;margin-bottom: 5px;">
                <el-button class="con_apply" type="primary" size="" @click="open('add')">{{$t('common.btn.add')}}</el-button>
              </el-col>
            </el-row>
            <edu-table ref="tables" :url="tableApi" :selection="false">
                <el-table-column :min-width="item.width" v-for="item in label" :key="item.props" :label="item.label" :prop="item.props" show-overflow-tooltip></el-table-column>
                <el-table-column width="120px" :label="$t('nonPublicCourseOpen.operation')" fixed="right">
                    <template slot-scope="scope">
                        <div class="con_btns" >
                            <el-button type="text" @click="open('edit', scope.row)">{{$t('common.btn.edit')}}</el-button>
                            <el-button type="text" @click="deletes(scope.row)">{{$t('common.btn.delete')}}</el-button>
                        </div>
                    </template>
                </el-table-column>
            </edu-table>
          </el-card>
        </div>
        <!-- 编辑 -->
        <el-dialog :visible.sync="dialogFlag" :title="titles" width="800px">
            <ruleSettingAdd v-if="dialogFlag" ref="ruleSettingAdd" :objs="objs" :options="options" @emit:back="applyBack"></ruleSettingAdd>
            <span slot="footer" class="dialog-footer">
                <el-button @click="dialogFlag = false" >{{$t('common.btn.cancel')}}</el-button>
                <el-button type="primary" @click="sure" >{{$t('common.btn.save')}}</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
import { timeSettingTableList, timeSettingDelete } from "common/src/api/paperBlindTrial";
import ruleSettingAdd from './ruleSettingAdd';
import commonMixins from 'common/src/views/practiceManagement/commonMixins';
export default {
    components: {
      ruleSettingAdd
    },
    mixins: [commonMixins],
    props: {},
    data() {
        return {
            tableApi: timeSettingTableList,
            dialogFlag: false,
            objs: {},
            queryForm: {
              // "manageDeptId": "2",  // 管理部门 非必填
              "academyCode": '',
              "batchNo": ''
            },
            label: [
              { label: this.$t('label.college'), props: 'academyCodeI18n', width: 100 },
              { label: this.$t('paperBlindTrial.batchName'), props: 'batchNo', width: 120 },
              { label: this.$t('message.startTime'), props: 'dateStart', width: 120 },
              { label: this.$t('message.endTime'), props: 'dateEnd', width: 100 },
            ],
            options: {
              academyCode: [] // 学院
            },
        };
    },
    computed: {

    },
    created() {
    },
    mounted() {
      // 获取数据字典数据
      let param = {
        X_YX: 'academyCode', // 学院
      };
      this.initOptions(param);
      this.onSubmit();
    },
    methods: {
      sure() { // 确定
          if (this.objs.id) {
            this.$refs.ruleSettingAdd.save('edit');
            return;
          }
          this.$refs.ruleSettingAdd.save();
      },
      open(val, row = {}) {
        if (val === 'edit') { // 编辑
          this.objs.id = row.id;
          this.titles = this.$t('common.btn.edit');
        } else { // 新增
          this.titles = this.$t('common.btn.add');
          this.objs = {};
        }
        this.dialogFlag = true;
      },
      deletes(row) { // 删除
        this.$delConfirm().then(() => {
          timeSettingDelete([row.id]).then(res => {
            if (res.code === 200) {
              this.$message.success(this.$t('common.tips.deleteSuccess'));
              this.reset();
            }
          });
        }).catch(e => { });
      },
      onSubmit() { // 筛选
        this.$refs.tables.pageNum = 1;
        this.$refs.tables.search(this.queryForm);
      },
      reset() {  // 重置
        for (const key in this.queryForm) {
          this.queryForm[key] = '';
        }
        this.onSubmit();
      },
      // 申请回调方法
      applyBack () {
        this.dialogFlag = false;
        this.reset();
      },
    }
};
</script>

<style scoped lang="scss">
.con {
    &_title {
        width: 100%;
        // border-bottom: solid #ccc 2px;
        padding: 20px;
        color: #2b3b4e;
        font-weight: bold;
    }
}
.btn_row {
  padding-top: 15px;
}
</style>

